<script>
import { useRouter, useRoute } from 'vue-router';
import { login, getUserinfo } from '@/api/org.js'
export default {
	data() {
		return {
			code: ''
		}
	},
	onLaunch: function () {
		console.log('App Launch')
		let langType = uni.getLocale()
		// console.log(langType, '判断用户机器语言类型')
		this.$getLang(langType ? langType : 'zh-Hans')
	},
	methods: {
		getUrlParam(value) {
			var url = decodeURI(window.location.href);
			var object = {};
			const searchParams = new URLSearchParams(url);
			// 获取 uerId 的值
			const uerId = searchParams.get('uerId');
			object.uerId = uerId
			return object[value];
		},
		// 获取网址的code
		queryString() {
			if (this.code != null || this.code != "") {
				getUserinfo(this.code).then(rsp => {
					if (rsp.statusCode == 200) {
						uni.setStorageSync('loginUser', rsp.data)
						uni.setStorageSync('wflow-token', rsp.data.token)
						uni.showToast({
							title: this.$t('webAuto.Welcome') + rsp.data.userName,
							icon: 'success'
						})
						uni.reLaunch({
							url: '/pages/submit/submit'
						})
					}
				}).catch(err => {
					return err
				})
			}
		}
	},
	onShow: function () {
		// 单点登录操作
		var params = new URLSearchParams(window.location.href.split("?")[1])
		// console.log(params, params.get('code'))
		this.code = params.get('code')
		// 免密登录
		let uerId = this.getUrlParam("uerId")
		uni.setStorageSync('uerId', uerId);
		var url = ((decodeURI(window.location.href)).split("#/")[1].split('?uerId')[0]);
		// 判断是单点还是免密
		if (!this.code) {
			// 免密码登录
			login(uerId).then(rsp => {
				// if (rsp.data == false) {
				// 	return
				// } else {
					console.log('rsp.data', rsp.data)
					//登录信息设置到本地
					rsp.data.deptName = rsp.data.position
					uni.setStorageSync('loginUser', rsp.data)
					uni.setStorageSync('wflow-token', rsp.data.token)
					uni.showToast({ title: this.$t('webAuto.Welcome')  + rsp.data.userName, icon: 'success' })
					uni.reLaunch({ url: url })
				// }
			}).catch(err => {
				uni.showToast({ title: this.$t('webAuto.LoginFailed'), icon: 'error' })
			})
		} else {
			this.queryString()
		}

	},
	onHide: function () {
		console.log('App Hide')
	},

}
</script>

<style lang="scss">
@tailwind base;
@tailwind components;
@tailwind utilities;
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */

page {
	background-color: #F4F5F7;
}

.w-button {
	border-radius: 48rpx;
	font-size: 32rpx !important;
	border: none;

	&::after {
		border: none;
	}
}

.w-click-hover {
	background-color: #F7F7F7;
}

//表单组件值只读样式
.w-form-input-rv {
	border-bottom: 1px solid #eeeeee;
	font-size: 32rpx;
	line-height: 70rpx;
	margin-left: 5px;
}

.over-tip {
	overflow: hidden;
	text-overflow: ellipsis;
	/* 设置文本溢出时显示省略号 */
	white-space: nowrap;
	line-height: 30px;
}

// uni-view{
// 	overflow: hidden;
// }

.uni-scroll-view{
	overflow-y: auto;
	margin-bottom: 120rpx;
}

//覆盖默认组件样式
:deep(.w-form-input) {
	font-size: 32rpx;
	//border: none;

	.is-input-border,
	.input-value-border {
		//border: none !important;
	}

	.uni-input-placeholder,
	.uni-input-wrapper,
	.placeholder,
	.input-value,
	.uni-date__x-input,
	.uni-textarea-placeholder,
	.uni-textarea-wrapper {
		font-size: 32rpx !important;
	}

	.is-disabled {
		background-color: white !important;
	}

}

/* #ifdef MP */
.wflow-form .uni-forms-item {
	padding: 0 16rpx 32rpx 16rpx;
	background-color: white;
	margin-bottom: 16rpx;
	font-size: 32rpx !important;

	.uni-forms-item__error {
		padding-top: 0 !important;
	}

	.uni-easyinput__content-input {
		height: 30px;
		font-size: 32rpx
	}

	.uni-easyinput__placeholder-class,
	.uni-date__x-input {
		font-size: 32rpx
	}

	.w-form-title {
		display: flex;
		align-items: center;
		padding: 13rpx 0;
	}
}

/* #endif */
</style>
